<?php
declare (strict_types=1);

namespace app\api\controller;

use app\model\WareModel;
use app\model\CategoryModel;
use think\facade\Request;
use think\facade\Validate;

class Category
{
    public function list()
    {
        $categoryList = CategoryModel::select();
        $data = [
            'status' => 0,
            'message' => '',
            'data' => [
                'categoryList' => $categoryList,
            ],
        ];
        
        foreach ($categoryList as &$item) {
            $wareList = WareModel::where('category_id', "=", $item['category_id'])->select();
            $item['wareList'] = $wareList->toArray();
        }
        unset($item);
        return json($data);   
    }
}
